package com.sskj.givecoin.v.activity;

import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.kaopiz.kprogresshud.KProgressHUD;
import com.sskj.givecoin.MyAppLication;
import com.sskj.givecoin.R;
import com.sskj.givecoin.common.App;
import com.sskj.givecoin.p.base.BasePresenter;
import com.sskj.givecoin.v.base.BaseActivity;

import butterknife.BindView;

/**
 * ProjectName：期权
 * DESC: (类描述)联系客服页面
 * Created by hqf on 2018/10/23 9:45
 * updateName:(修改人名称)
 * updateTime:(修改时间)
 * updateDesc:(修改内容)
 */
public class CustomerServiceActivity extends BaseActivity {
    @BindView(R.id.webView)
    WebView webView;

    private KProgressHUD progress;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_customer_service;
    }

    @Override
    public BasePresenter getPresenter() {
        return new BasePresenter();
    }

    @Override
    protected void onViewBinding() {
        super.onViewBinding();
        init();
    }

    /**
     * 设置加载页面
     */
    private void setLoadingView() {
        progress = KProgressHUD.create(this)
                .setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
                .setLabel(App.INSTANCE.getString(R.string.strCustomerServiceActivity200))
                .setCancellable(true)
                .show();
    }

    public void init() {
        String url = "";
        if ("english".equals(MyAppLication.getLANGUAGE())) {
            url = "file:///android_asset/services_en.html";
        } else {
            url = "file:///android_asset/services_cn.html";
        }
        setLoadingView();
        //覆盖WebView默认通过第三方或者是系统浏览器打开网页的行为，使得网页可以在WebView中打开
        webView.loadUrl(url);
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);//允许使用js
        webSettings.setDisplayZoomControls(false);
        webSettings.setDomStorageEnabled(true);
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);//不使用缓存，只从网络获取数据.
        //支持屏幕缩放
        webSettings.setSupportZoom(true);
        webSettings.setBuiltInZoomControls(true);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                progress.dismiss();
            }
//            @Override
//            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
//                view.loadUrl(url);
//                return super.shouldOverrideUrlLoading(view, request);
//            }
        });

    }


}
